//获取批次列表api
function getListings(groupId,callback){
  if (typeof (groupId)=='undefined') return null;
  let that = this;
  let result = null;
  wx.request({
    url: getApp().globalData.host + 'listing/list',
    header: getApp().globalData.header,
    data: { 'groupId': groupId },
    method: 'POST',
    success: function (res) {
      if (typeof (res.data.records) != "undefined") {
        for (let i = 0; i < res.data.records.length; i++) {
          res.data.records[i].price = (res.data.records[i].currentAmount / res.data.records[i].quantity).toFixed(2);
        }
        callback(res.data.records);
      }
    },
    fail: function (res) { }
  })
  return result;
}

//获取SKU信息
function getSku(skuId, callback){
  if (typeof (skuId) == 'undefined') return null;
  let that = this;
  wx.request({
    url: getApp().globalData.host + 'webapp/resource/getSku.html',
    header: getApp().globalData.header,
    data: { 'skuId': skuId },
    success: function (res) {
      if (typeof (res.data) != 'undefined' && res.data != '') {
        callback(res.data);
      }
    }
  })
}

//获取当前挂牌组信息
function getCurrentGroup(groupId,callback){
  wx.request({
    url: getApp().globalData.host + 'listing/currentGroup',
    header: getApp().globalData.header,
    data: { 'groupId': groupId },
    method: 'POST',
    success: function (res) {
      if (typeof (res.data) != "undefined") {
        callback(res.data);
      }
    }
  })
}

module.exports = {
  getListings: getListings,
  getSku: getSku,
  getCurrentGroup: getCurrentGroup
}